package com.ysxsoft.wdg.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.Toast;

/**
 * 吐司工具类
 */
public class ToastUtils {
    private static Toast sToast;
    @SuppressLint("StaticFieldLeak")
    private static Context mContext;

    @SuppressLint("ShowToast")
    private static Toast getInstance() {
        synchronized (ToastUtils.class) {
            if (sToast == null) {
                sToast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
            }
        }
        return sToast;
    }

    public static void init(Context context) {
        mContext = context;
    }

    public static void showToast(String text) {
        getInstance().setText(text);
        getInstance().setDuration(Toast.LENGTH_SHORT);
        getInstance().show();
    }
}
